package com.oritsh.dicom.wado.service;

import com.oritsh.dicom.scp.StoreSCP;
import com.oritsh.dicom.scu.DicomStreamStore;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.security.GeneralSecurityException;

/**
 * Created by xiashenpin on 16/1/31.
 */
public class StoreService {
    String aeTitle = "StoreSP";
    int port = 11112;
    DicomStreamStore streamStore;

    StoreSCP storeSCP;

    @PostConstruct
    public void setup(){

        try {
            storeSCP = new StoreSCP(getAeTitle(),getPort());
            storeSCP.setDicomStreamStore(streamStore);
            storeSCP.bind();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
        }
    }

    @PreDestroy
    public void clean(){
        if (storeSCP!=null){
            try {
                storeSCP.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    public String getAeTitle() {
        return aeTitle;
    }

    public void setAeTitle(String aeTitle) {
        this.aeTitle = aeTitle;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public StoreSCP getStoreSCP() {
        return storeSCP;
    }

    public DicomStreamStore getStreamStore() {
        return streamStore;
    }

    public void setStreamStore(DicomStreamStore streamStore) {
        this.streamStore = streamStore;
    }
}
